package com.csd.adapter;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.csd.activity.R;
import com.csd.bean.Car;

public class CarTypeAdapter extends BaseAdapter {

	private List<Car> list;
	private Context context;
	
	
	public CarTypeAdapter(List<Car> list, Context context) {
		super();
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@SuppressLint("ViewHolder")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View view = null;
		if(convertView == null){
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(R.layout.cartype_item, null);
		}else{
			view = convertView;
		}
		TextView text = (TextView) view.findViewById(R.id.car_text);
		ImageView img = (ImageView) view.findViewById(R.id.car_img);
		Car carType = list.get(position);
		if(position == 0 || position == 1){
			text.setText(carType.getCarBrand());
			text.setTextSize(20);
		}else{
			text.setText(carType.getCarBrand());
			img.setImageDrawable(context.getResources().getDrawable(carType.getImg()));
		}
		
		return view;
	}

}
